{extend name="common:base" /}


{block name="breadcrumb"}
<h1>
    管理员管理
    <small>管理员管理</small>
</h1>
<ol class="breadcrumb">
    <li><a href="{:url('/admin')}"><i class="fa fa-dashboard"></i> 控制台</a></li>
    <li><a href="{:url('/admin/admin_user')}">管理员管理</a></li>
    <li class="active">编辑管理员</li>
</ol>
{/block}


{block name="content"}
<!-- Default box -->

<form action="{:url('/admin/admin_user/edit')}" method="post" style="display: block;" id="formDocument">
    <div class="row">
        <!-- left column -->
        <div class="col-md-8">
            <!-- Horizontal Form -->
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">基本信息</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <div class="form-horizontal">

                    <input name="id" value="{$info.id}" type="hidden">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">昵称</label>
                            <div class="col-sm-9">
                                <input type="text" name="nickname" class="form-control" id="inputNickname" placeholder="昵称" value="{$info.nickname}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户名</label>
                            <div class="col-sm-9">
                                <input type="text" name="username" class="form-control" id="inputUsername" placeholder="用户名" value="{$info.username}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">邮箱</label>
                            <div class="col-sm-9">
                                <input type="email" name="email" class="form-control" id="inputEmail" placeholder="邮箱" value="{$info.email}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-9">
                                <input type="password" name="password" class="form-control" id="inputPassword" placeholder="留空表示不修改">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">确认密码</label>

                            <div class="col-sm-9">
                                <input type="password" name="confirm_password" class="form-control" id="inputConfirmPassword" placeholder="确认密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否启用</label>
                            <div class="col-sm-9">
                                <label><input type="checkbox" name="status" class="flat-red" value="1" checked> </label>
                            </div>
                        </div>

                    </div>
                    <!-- /.box-body -->

                    <!-- /.box-footer -->
                </div>
            </div>
            <!-- /.box -->
        </div>

        <!--/.col (left) -->
        <!-- right column -->
        <div class="col-md-4">
            <!-- general form elements -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">其他信息</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <div class="box-body">
                    <div class="form-group">
                        <label>上传头像</label>
                        <div class="upload-box">
                            <img class="upload-box-img" src="{$info.avatar|default='/static/admin/dist/img/upload-pic.png'}">
                            <input class="upload-box-input" type="hidden" name="avatar" value="{$info.avatar}">
                            <input class="upload-input" type="file" id="file" name="file">
                        </div>
                        <p class="help-block">选择一张图片作为头像.</p>
                    </div>


                </div>
                <!-- /.box-body -->
            </div>
            <!--&lt;!&ndash; /.box &ndash;&gt;-->
        </div>
        <!--/.col (right) -->
        <div class="col-sm-12 p10">
            <div class="submit-box p10">
                <button type="submit" class="btn btn-danger">提交</button>
                <button type="button" class="btn btn-default btn-cancel">取消</button>
            </div>
        </div>

    </div>
</form>
<!-- /.box -->
{/block}
{block name="js"}
<script src="/static/admin/dist/js/ajaxfileupload.js"></script>
<script>
    $("#formDocument").validate({
        rules: {
            username: 'required',
            email: {
                required: true,
                email: true
            },
            confirm_password: {
                equalTo:"#inputPassword"
            }
        },
        messages: {
            username: "请输入用户名",
            email: "请输入一个正确的邮箱",
            confirm_password: {
                equalTo: "两次密码输入不一致"
            }

        }
    });
    $('.upload-input').change(function () {
        var pDom = $(this).parent();
        $.ajaxFileUpload({
            url: '/admin/upload', //用于文件上传的服务器端请求地址
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file', //文件上传域的ID
            dataType: 'json', //返回值类型 一般设置为json
            success: function (data, status) {
                var path = data.file_path;
                //console.log(_this.parent());
                pDom.find('img.upload-box-img').attr('src',path);
                pDom.find('input.upload-box-input').val(path);
            },
            error: function (data, status, e) {
                alert(e);
            }
        })
    });
</script>
{/block}